<template>
	<view class="p30">
		<view class="card-cell-box pb20">
			<title-bar title="填写内容"></title-bar>
			<u--textarea v-model="content" placeholder="请在此输入内容,200字以内" border="none"></u--textarea>
		</view>
		<view class="card-cell-box mt30  pb20">
			<view class="flex-between">
				<title-bar title="上传图片"></title-bar>
				<text class="c-info f20">最多3张，建议小于2MB</text>
			</view>
			<view class="mt10">
				<u-upload ref="upload" accept="image" :fileList="fileList" name="1" multiple :maxCount="3" @delete="deleteFun" @afterRead="afterRead"
					:previewFullImage="true"></u-upload>
			</view>
			<!-- <view class="c-info f20 mt10 flex-align-center">
				<view class="c-danger mr4">*</view>请先等图片上传完成在点击提交
			</view> -->

		</view>
		<view class="card-cell-box mt30  flex-between">
			<title-bar title="联系方式"></title-bar>
			<u--input placeholder="请输入您的联系方式" border="none" v-model="phone" type="number" inputAlign="right"></u--input>
		</view>
		<view class="flex-center">
			<view style="width: 150px;" class="mt100">
				<u-button type="primary" text="保存" :throttleTime="1000" @click="addFeedbackFun"></u-button>
			</view>
		</view>

	</view>
</template>

<script>
	import TitleBar from "../../components/title-bar";
	import {
		addFeedbackAPI
	} from "@/api/api/feedback";

	import uploadMixins from "@/pagesMy/uploadMixins.js"
	import {
		throttle
	} from '@/utils/utils.js'
	import {
		mapState
	} from 'vuex'
	
	export default {
		mixins:[uploadMixins],
		components: {
			TitleBar
		},
		data() {
			return {
				content: '',
				phone: '',
			}
		},
		computed: {
			...mapState(["loginUser"]), 
		},
		onShow(){
			this.phone = this.loginUser.phone;
			this.$store.commit("setSpecialAppOnShow",false); 
		},
		methods: {
			addFeedbackFun:throttle(function(){
				let phone = /^1\d{10}$/;
				if (this.content == '') {
					this.$showToast("请输入反馈内容");
					return;
				}
				if (this.phone!="" && !phone.test(this.phone)) {
					this.$showToast("请输入正确的手机号码");
					return;
				}
				addFeedbackAPI({
					content: this.content,
					customerTel: this.phone,
					customerAttachList: this.requestFileList
				}).then(([err,data])=>{
					this.$showToast("添加成功");
					this.$navigateBackDuration(1);
				})
			}),
			$navigateBackDuration(delta, duration = 1500) {
				let pages = getCurrentPages();
				let prevPage = pages[ pages.length - 2 ];  
				prevPage.$vm.isRefresh = true;
				setTimeout(() => {
					uni.navigateBack({
						delta: delta
					})
				}, duration)
			}
		}

	}
</script>

<style>
</style>
